package mlp.game.scootaloo;

import java.util.ArrayList;

import com.overkill.game.GameEngine;
import com.overkill.game.Sprite;

import android.graphics.Paint;
import mlp.game.scootaloo.Obstacle.Type;

public class ObstacleSpawner {

	Sprite cupcakes[];
	Sprite groundObstacles[];
	Sprite airObstacles[];
	
	float ground;
	Paint shadowPaint;
	
	float obstacleMeter = 0;
	float distanceToSpawn = GameEngine.dip(500f);
	boolean spawnFlag = false;
	
	public ObstacleSpawner(Sprite cupcakes[], Sprite groundObstacles[], Sprite airObstacles[], float ground, Paint shadowPaint) {
		this.cupcakes = cupcakes;
		this.groundObstacles = groundObstacles;
		this.airObstacles = airObstacles;
		this.ground = ground;
		this.shadowPaint = shadowPaint;
		this.obstacleMeter = 0;
		this.distanceToSpawn = GameEngine.dip(500f);
		this.spawnFlag = false;
	}
	
	public synchronized void spawn(ArrayList<Obstacle> list){
		if(ScootalooEngine.scoreDistance > obstacleMeter + distanceToSpawn){
			obstacleMeter = obstacleMeter + distanceToSpawn;
			double spawnRandom = Math.random();
			if(spawnRandom < 0.5){
				list.add(new Obstacle(cupcakes, Type.CUPCAKE, ground, shadowPaint));
			} else {
				if(spawnFlag == false){
					double spawnType = Math.random();
					if(spawnType < 0.1)
						list.add(new Obstacle(airObstacles, Type.DERPY, ground, shadowPaint));	
					else
						list.add(new Obstacle(groundObstacles, Type.OBSTACLE, ground, shadowPaint));	
					spawnFlag = true;
				} else {
					spawnFlag = false;
				}
			}
		}
	}
}
